package com.qfedu.fmmall.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.qfedu.fmmall.vo.ResStatus.NO;
import static com.qfedu.fmmall.vo.ResStatus.OK;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "ResultVO对象",description = "封装接口返回给前端的数据")
public class ResultVO <T>{

    //响应给前端的状态码
    @ApiModelProperty(value = "响应状态码,成功:10000,失败:10001",dataType = "int")
    private int code;

    //响应给前端的提示信息
    @ApiModelProperty(value = "响应提示信息",dataType = "String")
    private String msg;

    //响应给前端的数据
    @ApiModelProperty("响应数据")
    private Object data;
    public static <T>ResultVO<T> success(T object,String msg){
        ResultVO ro=new ResultVO<>();
        ro.code=OK;
        ro.data = object;
        ro.msg = msg;
        return ro;
    }
    public static <T> ResultVO error(String msg){
        ResultVO ro=new ResultVO<>();
        ro.code=NO;
        ro.msg = msg;
        return ro;
    }
}
